﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Common.UI.Controls
{
    public class BooleanNegatorConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Boolean? booleanNullable = value as Boolean?;
            if (booleanNullable != null && !booleanNullable.HasValue)
            {
                return booleanNullable;
            }

            Boolean valueBool = false;
            if (booleanNullable == null)
            {
                valueBool = (Boolean)value;
            }
            else
            {
                valueBool = booleanNullable.Value;
            }

            return !valueBool;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        #endregion
    }
}
